<template>
	<view class="page-body" :class="[app.setCStyle()]">
		<!-- #ifdef MP-WEIXIN -->
<!-- 		<u-navbar :is-back="false" title-width="700" :title="pageInfo.page.title" title-color="#fff"
		 :background="{ background: '#000000' }" :border-bottom="false"></u-navbar> -->
		<!-- #endif -->
		<view class="u-page">
			<view v-if="is_diy == 0" class="page-body">
				默认商城
			</view>
			<view v-else class="page-body" :style="{background:pageInfo.page.background}">
				<diyPage :pageInfo="pageInfo"></diyPage> 
				<a href="https://beian.miit.gov.cn/" target="_blank" style="text-align: center;color: #BCBCBC;font-size: 13px;text-decoration:none;display: block;margin-top:10px">粤ICP备2025408433号-2</a>
				<!-- <a href="https://beian.miit.gov.cn/" target="_blank" style="text-align: center;color: #BCBCBC;font-size: 13px;text-decoration:none;display: block;">备案号：粤公网安备 粤ICP备2023108683号-1</a><br> -->
				
			</view>
		</view>
		<tabbar :_current="0" :getCartNum="0"></tabbar>
	</view>
	
	

</template>


<script>
	import tabbar from '@/pages/shop/tabbar';
	import diyPage from '@/pages/shop/index/diyPage/index';
	export default {
		components: {
			tabbar,
			diyPage
		},
		data() {
			return {
				is_diy: -1,
				pageInfo: {
					page: {}
				},
				share_title:'',
				share_desc:'',
				share_image:''
			};
		},
		onLoad(options) {
			this.loadData();
			uni.hideTabBar()
		},
		onShow(){
		},
		onHide(){
		},
		// #ifdef MP
		onShareAppMessage: function () {
			let that = this;
			let share_token = uni.getStorageSync("share_token");
			return {
				title: that.share_title || '',
				imageUrl: that.share_image || '',
				path: '/pages/shop/index/index?share_token=' + share_token
			};
		},
		onShareTimeline() {
			let that = this;
			let share_token = uni.getStorageSync("share_token");
			return {
				title: that.share_title || '',
				query: {
					share_token: share_token
				},
				imageUrl: that.share_image || '',
			};
		},
		// #endif
		methods: {
			//请求数据
			async loadData() {
				this.$u.post('shop/api.Index/getIndexInfo').then(res => {
					this.is_diy = res.data.is_diy;
					this.pageInfo = res.data.page;
					this.share_title = this.pageInfo.page.title
					this.share_desc = this.pageInfo.page.desc
					this.share_image = this.pageInfo.page.icon
					uni.setNavigationBarTitle({
						title:this.pageInfo.page.title
					})
					this.getShare()
					//console.log(this.pageInfo);
				})
			},
			getShare() {
				let _this = this;
			 
				// js-sdk文档中规定，url的格式要求：
				// 确认url是页面完整的url(请在当前页面alert(location.href.split('#')[0])确认)，包括'http(s): '部分，以及'？'后面的GET参数部分,但不包括'#'hash后面的部分
				var url = location.href.split('#')[0];
				this.$u.post('/publics/api.index/getWxShare', {
					url: url,
				}).then(res => {
					uni.hideLoading();
					var shareConfig = res.data;
					_this.$wxjs.config({
						debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
						appId: res.data.wxShare.appId, // 公众号的唯一标识  
						timestamp: res.data.wxShare.timestamp, // 生成签名的时间戳  
						nonceStr: res.data.wxShare.nonceStr, // ，生成签名的随机串  
						signature: res.data.wxShare.signature, // 签名  
						// surl: res.data.surl, //自己添加的，debug为true的时候可以网页打印出对应的URL是否正确
						jsApiList: ['updateAppMessageShareData','updateTimelineShareData']})
						_this.$wxjs.ready(() => {
							let links = window.location.href;
							let shareLink = ''
							if (links.indexOf('share_token') < 0){
								if (links.indexOf('?') > 0){
									shareLink = links + '&share_token=' + res.data.token; 
								}else{
									shareLink = links + '?share_token=' + res.data.token; 
								}
							}else{
								shareLink = links;
							}

							_this.$wxjs.updateAppMessageShareData({
								title: _this.share_title?_this.share_title:'', // 分享标题 
								desc: _this.share_desc?_this.share_desc:'', // 分享描述  
								link: shareLink, // 当前页面链接  
								imgUrl: _this.share_image?_this.share_image:'', // 分享图标   
								success(res) {
	
								},
								cancel(res) {}
							})
							// 自定义“分享到朋友圈”及“分享到QQ空间”按钮的分享内容（1.4.0）
							_this.$wxjs.updateTimelineShareData({
								title: _this.share_title?_this.share_title:'', // 分享标题  
								desc: _this.share_desc?_this.share_desc:'', // 分享描述  
								link: shareLink, // 当前页面链接  
								imgUrl: _this.share_image?_this.share_image:'', // 分享图标   
								success(res) {},
								cancel(res) {}
							})
						})
					}).catch(err => {
						console.log(err);
				})
			}
		}
	}
</script>

<style lang='scss'>
</style>
